package com.kgc.controller;

import com.kgc.basic.pojo.BOM;
import com.kgc.basic.util.ResponseMsg;
import com.kgc.feign.BOMFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Controller
@CrossOrigin
@RequestMapping("/BOM")
public class BOMController {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private BOMFeign bomFeign;

    @RequestMapping("getBOMPage")
    @ResponseBody
    ResponseMsg getBOMPage(String pageNow,String pageSize,String name) {
        logger.info("BOMController getBOMPage pageNow={},pageSize={},name={}",pageNow,pageSize,name);
        Map<String,Object> map = new HashMap<>();
        map.put("pageNow",pageNow);
        map.put("pageSize",pageSize);
        map.put("name",name);
        ResponseMsg responseMsg = bomFeign.getBOMPage(map);
        logger.debug("bomService getBOMPage responseMsg={}", responseMsg+",map="+map);
        return responseMsg;
    }
    @RequestMapping("addBOM")
    @ResponseBody
    ResponseMsg addBOM(@RequestBody BOM bom){
        logger.info("BOMController addBOM bom={}", bom);
        ResponseMsg responseMsg = bomFeign.addBOM(bom);
        logger.debug("bomService addBOM responseMsg={}", responseMsg);
        return responseMsg;
    }
    @RequestMapping("updateBOM")
    @ResponseBody
    ResponseMsg updateBOM(@RequestBody BOM bom){
        logger.info("BOMController updateBOM bom={}", bom);
        ResponseMsg responseMsg = bomFeign.updateBOM(bom);
        logger.debug("bomService updateBOM responseMsg={}", responseMsg);
        return responseMsg;
    }
    @RequestMapping("delBOM")
    @ResponseBody
    ResponseMsg delBOM(String id){
        logger.info("BOMController delBOM bom={}", id);
        ResponseMsg responseMsg = bomFeign.delBOM(id);
        logger.debug("bomService delBOM responseMsg={}", responseMsg);
        return responseMsg;
    }
    @RequestMapping("getBOMById")
    @ResponseBody
    public ResponseMsg getBOMById(String id){
        logger.info("BOMController getBOMById bom={}", id);
        ResponseMsg responseMsg = bomFeign.getBOMById(id);
        logger.debug("bomService getBOMById responseMsg={}", responseMsg);
        return responseMsg;
    }
    @RequestMapping("getAllBOM")
    @ResponseBody
    public ResponseMsg getAllBOM(){
        logger.info("BOMController getAllBOM start...");
        ResponseMsg responseMsg = bomFeign.getAllBOM();
        logger.debug("bomService getAllBOM responseMsg={}", responseMsg);
        return responseMsg;
    }
}
